<template>
    <div id="OrdersTitle">
        <v-details :inputConfig="inputConfig" :detailData="inputData" :rules="rules" ref="input"
                   @pop="setdata"></v-details>
    </div>
</template>

<script>
    import details from 'commons/Detail'
    import baseMixin from "@/mixins/BaseMixin";

    export default {
        props: {
            inputData: {
                type: Object,
            }
        },
        mixins: [baseMixin],
        name: "OrdersTitle",
        data() {
            return {
                addflag: false,
                flag1: true,
                flag2: true,
                rules: {
                    cost_code: [
                        {required: true, trigger: 'blur'},
                    ],
                    cost_desc: [
                        {required: true, trigger: 'blur'},
                    ],
                    cost_type_code: [
                        {required: true, trigger: 'blur'},
                    ],
                    cost_group: [
                        {required: true, trigger: 'blur'},
                    ],
                },
            }
        },
        computed: {
            inputConfig() {
                return [
                    [
                        {
                            type: "input",
                            label: "成本代码",
                            props: "cost_code",
                            disabled: this.addflag
                        },
                        {
                            type: "input",
                            label: "成本说明",
                            props: "cost_desc",
                        },
                        {
                            type: "select",
                            label: "成本类型",
                            props: "cost_type_code",
                            options: this.getOptions("queryCodeCostType/zh")
                        },
                        {
                            type: "select",
                            label: "成本组",
                            props: "cost_group",
                            options: this.getOptions("queryCostGroup")
                        },
                        {
                            type: "table",
                            label: "默认公司",
                            props: "def_db_corp",
                            tableConfig: [
                                {
                                    label: this.$t("bill.corpCode"),
                                    prop: "corp_code",
                                    input: "input",
                                },
                                {
                                    label: this.$t('common.desc'),
                                    prop: "corp_name",
                                    input: "input",
                                },
                            ],
                            url: `/queryCorporation/?/${this.$store.state.wms}`
                        },
                        {
                            type: "table",
                            label: "默认部门",
                            props: "def_db_dept",
                            tableConfig: [
                                {
                                    label: this.$t("config.departCode"),
                                    prop: "dept_code",
                                    input: "input",
                                },
                                {
                                    label: this.$t('common.desc'),
                                    prop: "dept_name",
                                    input: "input",
                                },
                            ],
                            disabled: this.flag1,
                            url: `/queryDepartment/${this.inputData.def_db_corp}/?/${this.$store.state.wms}`

                        },
                        {
                            type: "table",
                            label: "默认账户",
                            props: "def_db_acct",
                            tableConfig: [
                                {
                                    label: this.$t("config.accountCode"),
                                    prop: "acct_code",
                                    input: "input",
                                },
                                {
                                    label: this.$t('common.desc'),
                                    prop: "acct_name",
                                    input: "input",
                                },
                            ],
                            disabled: this.flag2,
                            url: `/queryAccount/${this.inputData.def_db_corp}/${this.inputData.def_db_dept}/?/${this.$store.state.wms}`
                        },
                    ],
                ]
            },
        },
        methods: {
            setdata(data, id, close, listId) {
                if (id == "4") {
                    this.inputData.def_db_corp = data.corp_code;
                } else if (id == "5") {
                    this.inputData.def_db_dept = data.dept_code;
                } else if (id == "6") {
                    this.inputData.def_db_acct = data.acct_code;
                }
                close(false);
            }
        },
        mounted() {
            if (Object.keys(this.$store.state.skip).length !== 0) {
                let data = this.$store.state.skip;
                if (!data.newFlag) {
                    this.addflag = true;
                }
            } else if (!this.$store.state.newFlag) {
                this.addflag = true;
            }
        },
        watch: {
            "inputData.def_db_corp"(data) {
                if (data != "") {
                    this.flag1 = false;
                } else {
                    this.flag1 = true;
                }
            },
            "inputData.def_db_dept"(data) {
                if (data != "") {
                    this.flag2 = false;
                } else {
                    this.flag2 = true;
                }
            }
        },
        components: {
            'v-details': details
        }
    }
</script>

<style scoped>

</style>
